﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Modulos/ModuloPrestamo/VistaControl/MasterPagePrestamo.master" AutoEventWireup="true" CodeFile="beneficiarios.aspx.cs" Inherits="Modulos_ModuloPrestamo_VistaControl_Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
Módulo de Préstamos - Administración de Beneficiarios
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <h2>Administrar Beneficiarios</h2>
    <asp:FormView ID="FormView1" runat="server" DataKeyNames="RUT_BEN" 
        DataSourceID="SqlDataSource1">
        <InsertItemTemplate>
            <table style="width: 100%" frame="box">
                <tr>
                    <td colspan="2">
                        Nuevo beneficiario</td>
                </tr>
                <tr>
                    <td>
                        RUT:</td>
                    <td>
                        <asp:TextBox ID="RUT_BENTextBox" runat="server" Text='<%# Bind("RUT_BEN") %>' />
                        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
                            ControlToValidate="RUT_BENTextBox" Display="Dynamic" 
                            ErrorMessage="* campo numérico" ValidationExpression="\d*"></asp:RegularExpressionValidator>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                            ControlToValidate="RUT_BENTextBox" Display="Dynamic" 
                            ErrorMessage="* campo obligatorio"></asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td>
                        Institución</td>
                    <td>
                        <asp:DropDownList ID="DropDownListInstBen" runat="server" 
                            DataSourceID="SqlDataSourceInstitucionesBen" 
                            DataTextField="NOMBRE_INST" 
                            SelectedValue='<%# Bind("INST_ID") %>'
                            DataValueField="INST_ID">
                        </asp:DropDownList>
                        
                        <asp:SqlDataSource ID="SqlDataSourceInstitucionesBen" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:AppCeiiConnectionString %>" 
                            SelectCommand="SELECT [INST_ID], [NOMBRE_INST] FROM [INSTITUCION]">
                        </asp:SqlDataSource>
                    </td>
                </tr>
                <tr>
                    <td>
                        Nombres:</td>
                    <td>
                        <asp:TextBox ID="NOMBRE_BENTextBox" runat="server" 
                            Text='<%# Bind("NOMBRE_BEN") %>' />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                            ControlToValidate="NOMBRE_BENTextBox" Display="Dynamic" 
                            ErrorMessage="* campo obligatorio"></asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td>
                        Ap. Paterno:</td>
                    <td>
                        <asp:TextBox ID="AP_PATERNO_BENTextBox" runat="server" 
                            Text='<%# Bind("AP_PATERNO_BEN") %>' />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
                            ControlToValidate="AP_PATERNO_BENTextBox" Display="Dynamic" 
                            ErrorMessage="* campo obligatorio"></asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td>
                        Ap. Materno:</td>
                    <td>
                        <asp:TextBox ID="AP_MATERNO_BENTextBox" runat="server" 
                            Text='<%# Bind("AP_MATERNO_BEN") %>' />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
                            ControlToValidate="AP_MATERNO_BENTextBox" Display="Dynamic" 
                            ErrorMessage="* campo obligatorio"></asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td>
                        Teléfono:</td>
                    <td>
                        <asp:TextBox ID="FONO_BENTextBox" runat="server" 
                            Text='<%# Bind("FONO_BEN") %>' />
                    </td>
                </tr>
                <tr>
                    <td>
                        Mail:</td>
                    <td>
                        <asp:TextBox ID="MAIL_BENTextBox" runat="server" 
                            Text='<%# Bind("MAIL_BEN") %>' />
                        <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" 
                            ControlToValidate="MAIL_BENTextBox" Display="Dynamic" 
                            ErrorMessage="* formato: usr@mail.net" 
                            ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;</td>
                    <td>
                        <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                            OnClientClick="javascript:if(!confirm('&iquest;Confirma ingresar beneficiario?'))return false"
                            CommandName="Insert" Text="Insertar" />
                        &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                            CausesValidation="False" CommandName="Cancel" Text="Cancelar" />
                    </td>
                </tr>
            </table>
        </InsertItemTemplate>
        <ItemTemplate>
            <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" 
                CommandName="New" Text="Nuevo benefiaciario" />
            <br />
        </ItemTemplate>
        <EmptyDataTemplate>
            <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" 
                CommandName="New" Text="Nuevo benefiaciario" />
        </EmptyDataTemplate>
    </asp:FormView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AppCeiiConnectionString %>" 
        DeleteCommand="DELETE FROM [BENEFICIARIO] WHERE [RUT_BEN] = @RUT_BEN" 
        InsertCommand="INSERT INTO [BENEFICIARIO] ([RUT_BEN], [INST_ID], [NOMBRE_BEN], [AP_PATERNO_BEN], [AP_MATERNO_BEN], [FONO_BEN], [MAIL_BEN]) VALUES (@RUT_BEN, @INST_ID, @NOMBRE_BEN, @AP_PATERNO_BEN, @AP_MATERNO_BEN, @FONO_BEN, @MAIL_BEN)" 
        ProviderName="<%$ ConnectionStrings:AppCeiiConnectionString.ProviderName %>" 
        SelectCommand="SELECT [RUT_BEN], [INST_ID], [NOMBRE_BEN], [AP_PATERNO_BEN], [AP_MATERNO_BEN], [FONO_BEN], [MAIL_BEN] FROM [BENEFICIARIO]" 
        UpdateCommand="UPDATE [BENEFICIARIO] SET [INST_ID] = @INST_ID, [NOMBRE_BEN] = @NOMBRE_BEN, [AP_PATERNO_BEN] = @AP_PATERNO_BEN, [AP_MATERNO_BEN] = @AP_MATERNO_BEN, [FONO_BEN] = @FONO_BEN, [MAIL_BEN] = @MAIL_BEN WHERE [RUT_BEN] = @RUT_BEN">
        <DeleteParameters>
            <asp:Parameter Name="RUT_BEN" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="RUT_BEN" Type="Int32" />
            <asp:Parameter Name="INST_ID" Type="Decimal" />
            <asp:Parameter Name="NOMBRE_BEN" Type="String" />
            <asp:Parameter Name="AP_PATERNO_BEN" Type="String" />
            <asp:Parameter Name="AP_MATERNO_BEN" Type="String" />
            <asp:Parameter Name="FONO_BEN" Type="String" />
            <asp:Parameter Name="MAIL_BEN" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="INST_ID" Type="Decimal" />
            <asp:Parameter Name="NOMBRE_BEN" Type="String" />
            <asp:Parameter Name="AP_PATERNO_BEN" Type="String" />
            <asp:Parameter Name="AP_MATERNO_BEN" Type="String" />
            <asp:Parameter Name="FONO_BEN" Type="String" />
            <asp:Parameter Name="MAIL_BEN" Type="String" />
            <asp:Parameter Name="RUT_BEN" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
                AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="RUT_BEN" 
                DataSourceID="SqlDataSource1" 
                EmptyDataText="No hay registros de datos para mostrar.">
                <Columns>
                    <asp:TemplateField ShowHeader="False">
                        <EditItemTemplate>
                            <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                            OnClientClick="javascript:if(!confirm('&iquest;Confirma actualizar beneficiario?'))return false"
                                CommandName="Update" Text="Actualizar"></asp:LinkButton>
                            &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                                CommandName="Cancel" Text="Cancelar"></asp:LinkButton>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                                CommandName="Edit" Text="Editar"></asp:LinkButton>
                            &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                            OnClientClick="javascript:if(!confirm('&iquest;Confirma eliminar beneficiario?'))return false"
                                CommandName="Delete" Text="Eliminar"></asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="RUT" SortExpression="RUT_BEN">
                        <EditItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Eval("RUT_BEN") %>'></asp:Label>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("RUT_BEN") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Intitución" SortExpression="INST_ID">
                        <EditItemTemplate>
                            <asp:DropDownList ID="DropDownList33" runat="server" 
                                DataSourceID="SqlDataSourceINT008" DataTextField="NOMBRE_INST" 
                                DataValueField="INST_ID" SelectedValue='<%# Bind("INST_ID") %>'>
                            </asp:DropDownList>
                            <asp:SqlDataSource ID="SqlDataSourceINT008" runat="server" 
                                ConnectionString="<%$ ConnectionStrings:AppCeiiConnectionString %>" 
                                SelectCommand="SELECT [NOMBRE_INST], [INST_ID] FROM [INSTITUCION]">
                            </asp:SqlDataSource>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:DropDownList ID="DropDownList2" runat="server" 
                                DataSourceID="SqlDataSourceInt001" DataTextField="NOMBRE_INST" 
                                DataValueField="INST_ID" Enabled="False" 
                                SelectedValue='<%# Bind("INST_ID") %>'>
                            </asp:DropDownList>
                            <asp:SqlDataSource ID="SqlDataSourceInt001" runat="server" 
                                ConnectionString="<%$ ConnectionStrings:AppCeiiConnectionString %>" 
                                SelectCommand="SELECT [INST_ID], [NOMBRE_INST] FROM [INSTITUCION]">
                            </asp:SqlDataSource>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Nombres" SortExpression="NOMBRE_BEN">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("NOMBRE_BEN") %>'></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" 
                                ControlToValidate="TextBox1" Display="Dynamic" 
                                ErrorMessage="* campo obligatorio"></asp:RequiredFieldValidator>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label2" runat="server" Text='<%# Bind("NOMBRE_BEN") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Ap. Paterno" SortExpression="AP_PATERNO_BEN">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("AP_PATERNO_BEN") %>'></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" 
                                ControlToValidate="TextBox2" Display="Dynamic" 
                                ErrorMessage="* campo obligatorio"></asp:RequiredFieldValidator>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label3" runat="server" Text='<%# Bind("AP_PATERNO_BEN") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Ap. Materno" SortExpression="AP_MATERNO_BEN">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("AP_MATERNO_BEN") %>'></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" 
                                ControlToValidate="TextBox3" Display="Dynamic" 
                                ErrorMessage="* campo obligatorio"></asp:RequiredFieldValidator>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label4" runat="server" Text='<%# Bind("AP_MATERNO_BEN") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="FONO_BEN" HeaderText="Teléfono" 
                        SortExpression="FONO_BEN" />
<asp:TemplateField HeaderText="Mail" SortExpression="MAIL_BEN"><EditItemTemplate>
                            <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("MAIL_BEN") %>'></asp:TextBox>
                        
                            <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" 
                                ControlToValidate="TextBox4" Display="Dynamic" 
                                ErrorMessage="* formato: usr@mail.net" 
                                ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
                        
</EditItemTemplate>
<ItemTemplate>
                            <asp:Label ID="Label5" runat="server" Text='<%# Bind("MAIL_BEN") %>'></asp:Label>
                        
</ItemTemplate>
</asp:TemplateField>
                </Columns>
            </asp:GridView>
    <br />
    <h2>Administrar Instituciones</h2>
    <br />
    <asp:FormView ID="FormView2" runat="server" DataKeyNames="INST_ID" 
        DataSourceID="SqlDataSource2">
        <InsertItemTemplate>
            <table style="width: 100%" frame="box">
                <tr>
                    <td colspan="2">
                        Nueva institución</td>
                </tr>
                <tr>
                    <td>
                        Nombre:</td>
                    <td>
                        <asp:TextBox ID="NOMBRE_INSTTextBox" runat="server" 
                            Text='<%# Bind("NOMBRE_INST") %>' />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" 
                            ControlToValidate="NOMBRE_INSTTextBox" Display="Dynamic" 
                            ErrorMessage="* campo obligatorio"></asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td>
                        Teléfono:</td>
                    <td>
                        <asp:TextBox ID="FONO_INSTTextBox" runat="server" 
                            Text='<%# Bind("FONO_INST") %>' />
                    </td>
                </tr>
                <tr>
                    <td>
                        Mail:</td>
                    <td>
                        <asp:TextBox ID="MAIL_INSTTextBox" runat="server" 
                            Text='<%# Bind("MAIL_INST") %>' />
                        <asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" 
                            ControlToValidate="MAIL_INSTTextBox" Display="Dynamic" 
                            ErrorMessage="* formato: usr@mail.net" 
                            ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;</td>
                    <td>
                        <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                        OnClientClick="javascript:if(!confirm('&iquest;Confirma ingresar institución?'))return false"
                            CommandName="Insert" Text="Insertar" />
                        &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                            CausesValidation="False" CommandName="Cancel" Text="Cancelar" />
                    </td>
                </tr>
            </table>
        </InsertItemTemplate>
        <ItemTemplate>
            <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" 
                CommandName="New" Text="Nueva institución" />
        </ItemTemplate>
        <EmptyDataTemplate>
            <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" 
                CommandName="New" Text="Nueva institución" />
        </EmptyDataTemplate>
    </asp:FormView>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:AppCeiiConnectionString %>"
        DeleteCommand="DELETE FROM [INSTITUCION] WHERE [INST_ID] = @INST_ID" InsertCommand="INSERT INTO [INSTITUCION] ([NOMBRE_INST], [FONO_INST], [MAIL_INST]) VALUES (@NOMBRE_INST, @FONO_INST, @MAIL_INST)"
        ProviderName="<%$ ConnectionStrings:AppCeiiConnectionString.ProviderName %>"
        SelectCommand="SELECT [INST_ID], [NOMBRE_INST], [FONO_INST], [MAIL_INST] FROM [INSTITUCION]"
        UpdateCommand="UPDATE [INSTITUCION] SET [NOMBRE_INST] = @NOMBRE_INST, [FONO_INST] = @FONO_INST, [MAIL_INST] = @MAIL_INST WHERE [INST_ID] = @INST_ID">
        <DeleteParameters>
            <asp:Parameter Name="INST_ID" Type="Decimal" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="NOMBRE_INST" Type="String" />
            <asp:Parameter Name="FONO_INST" Type="String" />
            <asp:Parameter Name="MAIL_INST" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="NOMBRE_INST" Type="String" />
            <asp:Parameter Name="FONO_INST" Type="String" />
            <asp:Parameter Name="MAIL_INST" Type="String" />
            <asp:Parameter Name="INST_ID" Type="Decimal" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="INST_ID"
        DataSourceID="SqlDataSource2" 
        EmptyDataText="No hay registros de datos para mostrar." AllowPaging="True" 
        AllowSorting="True">
        <Columns>
            <asp:TemplateField ShowHeader="False">
                <EditItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True"
                    OnClientClick="javascript:if(!confirm('&iquest;Confirma actualizar institución?'))return false" 
                        CommandName="Update" Text="Actualizar"></asp:LinkButton>
                    &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                        CommandName="Cancel" Text="Cancelar"></asp:LinkButton>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                        CommandName="Edit" Text="Editar"></asp:LinkButton>
                    &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                    OnClientClick="javascript:if(!confirm('&iquest;Confirma eliminar institución?'))return false"
                        CommandName="Delete" Text="Eliminar"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="INST_ID" HeaderText="Id" ReadOnly="True" 
                SortExpression="INST_ID" />
            <asp:TemplateField HeaderText="Nombre" SortExpression="NOMBRE_INST">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("NOMBRE_INST") %>'></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" 
                        ErrorMessage="* campo obligatorio" ControlToValidate="TextBox1" 
                        Display="Dynamic"></asp:RequiredFieldValidator>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("NOMBRE_INST") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="FONO_INST" HeaderText="Teléfono" 
                SortExpression="FONO_INST" />
            <asp:TemplateField HeaderText="Mail" SortExpression="MAIL_INST">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("MAIL_INST") %>'></asp:TextBox>
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator5" runat="server" 
                        ControlToValidate="TextBox2" Display="Dynamic" 
                        ErrorMessage="* formato: usr@mail.com" 
                        ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("MAIL_INST") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
</asp:Content>

